#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void
print_rev(char **arg)
{
	int i = 0;

	while (arg[i])
		++i;
	while (i--)
		printf("%s\n", arg[i]);
}

int
my_strcmp(const void *p1, const void *p2)
{
	return strcmp(* (char * const *) p1, * (char * const *) p2);
}

void
my_sort(char **arg)
{
	char **new_;
	int i = 0, j = 0;

	while (arg[i]) ++i;

	new_ = (char**) malloc(8 + i * sizeof(char*));
	while (j <= i) {
		new_[j] = arg[j];
		++j;
	}
	qsort(new_, (size_t) i - 1, sizeof(char*), my_strcmp);
	print_rev(new_);
	free(new_);
}

void
my_cool_strstr(char **pmass)
{
	int i = 0, stop;
	int n1, n2;
	char *in_start, *in_end;

	(void) scanf("%d%d", &n1, &n2);
	in_start = strstr(pmass[n2], pmass[n1]);
	in_end = in_start + strlen(pmass[n1]);
	stop = in_start - pmass[n2];
	printf("%d ", stop);
	while (i < stop)
		putchar(pmass[n2][i++]);
	putchar(' ');
	stop += strlen(pmass[n1]);
	while (i < stop)
		putchar(pmass[n2][i++]);
	putchar(' ');
	(void) printf("%s", in_end);
	putchar('\n');
}

int
main(void)
{
	char sentence[8192];
	int word_count = 0;
	int i = 0;
	char **pmass;
	void *tmp_ptr;

	pmass = (char**) malloc(sizeof(char*));
	*pmass = NULL;
	fgets(sentence, 8191, stdin);
	while (i < strlen(sentence)) {
		if (sentence[i] != ' '
		    && sentence[i] != '\n'
		    && sentence[i] != '.') {
			++i;
			continue;
		}

		/*
		 * Если мы попали сюда, то мы наткнулись на
		 * конец слова.
		 */
		if (*pmass == NULL) { /* нет первого слова */
			++word_count;
			pmass[0] = (char*) malloc(strcspn(sentence, " \n\t") + 2);
			sscanf(sentence, "%s", *pmass);
			pmass = (char**) realloc(pmass, (word_count+1) * sizeof(char*));
		}
		++word_count;
		tmp_ptr = realloc(pmass, (word_count+1) * sizeof(char*));
		if (tmp_ptr)
			pmass = (char**) tmp_ptr;
		else
			(void) fprintf(stderr, "Out of memory\n");
		pmass[word_count] = NULL;
		pmass[word_count - 1] = (char*) malloc(strcspn(&sentence[i+1], "\n \t") + 2);
		sscanf(&sentence[i+1], "%s", pmass[word_count-1]);
		++i;
	}
	print_rev(pmass);
	my_sort(pmass);
	my_cool_strstr(pmass);

	i = 0;
	while (pmass[i])
		free(pmass[i++]);
	free(pmass);
	return 0;
}
